
<!DOCTYPE html>
<html>
{[include file="_header.tpl"]}
<body>

<header class="navbar navbar-fixed-top bs-docs-nav">
    {[include file="_nav.tpl"]}
</header>

<main id="main" role="main">

    <div class="container docs-wrapper">
        <div class="row">

            <section id="content" class="col-lg-9 col-md-8 col-sm-8 col-xs-12">
                <h3>登录</h3>
                <form method="post" id="form_login" name="form_login">
				<table class="table table-bordered">
					<tr>
						<td class="col-lg-3 col-sm-4 col-xs-5" align="right">帐号：</td>
						<td class="col-lg-9 col-sm-8 col-xs-7"><input type="text" name="username" id="username" value="" size="20" placeholder="请输入上网帐号" /></td>
					</tr>
					<tr>
						<td align="right">密码：</td>
						<td><input type="password" name="password" id="password" value="" size="20" placeholder="请输入上网密码"/></td>
					</tr>
					<tr>
						<td align="right"></td>
						<td><input type="checkbox" name='remind_password' id='remind_password'>记住用户名和密码</td>
					</tr>
					<tr>
						<td></td>
						<td><input type="button" value="登 录" name="button_login" id="button_login" onclick="login();">
							<input type="reset" value="复 位" name="B2">
						</td>
					</tr>

				</table>
			</form>

            </section>

            <aside id="sidebar" class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
                {[include file="_left.tpl"]}
            </aside>

        </div>
    </div>
</main>

{[include file="user/_footer.tpl"]}

<script type="text/javascript">

$(function() {
	
	var username = $.cookie('username');
	var password = $.cookie('password');
	var remind_password = $.cookie('remind_password');
	
	if (remind_password == 'checked') {
		$("#remind_password").attr("checked", true);
	}
	
	$("#username").val(username);
	$("#password").val(password);
	
});

function login() {
	$("#button_login").attr('disabled', true); 
	$("#button_login").val("正在登录...");
	
	setTimeout(function() {
		_login();
		
	}, 500);
}

function _login() {
	var body = $('#form_login').formSerialize();
	// alert(body);
	
	$.getJSON('?do=User.exist', body, function(json) {
		
		var msg = '';
		if (json.status == 1) {
			remind();
			
			window.open('?do=User.loginPost&'+body, '_self');
			return true;
		} else if (json.status == 2) {
			msg = "登录失败！帐号不存在，请重新输入！";
		} else if (json.status == 3) {
			msg = "登录失败！帐号异常，请联系管理员！";
		} else if (json.status == 4) {
			msg = "登录失败！密码有误，请重新输入！";
		} else if (json.status == 9) {
			msg = "登录失败！帐号与密码不能为空，请重新输入！";
		}
		
		$("#button_login").attr('disabled', false);
		$("#button_login").val("登 录");
		alert(msg);
		
		return false;
	}, 'json');	
}
	
function remind() {
	
	if ($("#remind_password").attr("checked")) {
		var username = $("#username").val();
		var password = $("#password").val();
		
		$.cookie('username', username, { expires: 7 }); 
		$.cookie('password', password, { expires: 7 });
		
		$.cookie('remind_password', 'checked', { expires: 7 });
	} else {
		$.cookie('username', '', { expires: -1 });
		$.cookie('password', '', { expires: -1 });
		$.cookie('remind_password', '', { expires: -1 });
	}
}

</script>

</body>
</html>
